package top.lishuoboy.javase.base.collection;

import cn.hutool.core.collection.ConcurrentHashSet;
import org.junit.Test;

import java.util.*;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * @author lishuoboy
 * @date 2022/5/23 2:46
 */
public class CollectionTest {

    @Test
    public void mapTest() {
        Map map;
        int size;

//         size = 3;
        size = 100;

        map = new HashMap();
//        map = new Hashtable<>();
//        map = new ConcurrentHashMap<>();
//        map = new LinkedHashMap<>();
//        map = new TreeMap<>();
//        map = new ConcurrentSkipListMap<>();
//        map = new Properties();

        for (int i = 0; i < size; i++) {
            map.put("" + (size - i), "val");
        }

        for (int i = 0; i < size; i++) {
            map.put("" + (size - i), "val2");
        }

        map.put(null, "val");

        for (Object entry : map.entrySet()) {
            System.out.println(entry);
        }
    }

    @Test
    public void setTest() {
        Set set;
        int size;

//        size = 3;
        size = 100;

        set = new HashSet();
        set = new ConcurrentHashSet();
        set = new LinkedHashSet();
        set = new TreeSet();
        set = new ConcurrentSkipListSet();
        set = new CopyOnWriteArraySet();

        for (int i = 0; i < size; i++) {
            set.add("" + (size - i));
        }

//        for (int i = 0; i < size; i++) {
//            set.add("" + (size - i));
//        }

//        set.add(null);

        for (Object val : set) {
            System.out.println(val);
        }
    }


    @Test
    public void listTest() {
        List list;
        int size;

//         size = 3;
        size = 1000;

        list = new ArrayList();
        list = new LinkedList();
        list = new CopyOnWriteArrayList();
        list = new Vector();
        list = new Stack();

        for (int i = 0; i < size; i++) {
            list.add("" + (size - i));
        }

//        for (int i = 0; i < size; i++) {
//            list.add("" + (size - i));
//        }

//        list.add(null);

        if (list instanceof Stack) {
            Stack stack = (Stack) list;
            for (int i = 0; i < size; i++) {
                System.out.println(stack.pop());
            }
        } else {
            for (Object val : list) {
                System.out.println(val);
            }
        }

    }

    @Test
    public void queueTest() {
        ArrayDeque queue;
        int size;

//         size = 3;
        size = 1000;

//        queue = new LinkedList();
        queue = new ArrayDeque();
//        queue = new ConcurrentLinkedQueue();
//        queue = new ConcurrentLinkedDeque();

        for (int i = 0; i < size; i++) {
            queue.add("" + (size - i));
        }

//        for (int i = 0; i < size; i++) {
//            queue.add("" + (size - i));
//        }

//        queue.add(null);

        for (Object val : queue) {
            System.out.println(val);
        }

        for (int i = 0; i < size; i++) {
            System.out.println(queue.poll());
//            System.out.println(queue.remove());

            System.out.println(queue.peek());
            System.out.println(queue.element());
        }
    }
}
